var wxRequest = require('../../utils/wxRequest')
var Common = require('../../utils/common');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    notPayBillList: [],
    totalFee: 0,
    billIdStr: "",
    mrRoom:null,
    
  },
  goto_house_bind: function () {
    if (this.data.mrRoom == null) {
      wx.navigateTo({
        url: '../house_bind/house_bind'
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
    var url = app.globalData.domain + "/client/community/getMrRoom";
    var parm = {
      token: wx.getStorageSync("token"),
      idCommunity: wx.getStorageSync("idCommunity")
    }
    wxRequest.postRequest(url, parm).then(res => {
      console.log("获取当前房屋", res.data);
      this.setData({
        mrRoom: res.data
      });

      var getNotPayByRoomUrl = app.globalData.domain + "/client/propertyBill/getHistory";
      var parm = {
        token: wx.getStorageSync("token"),
        idRoom: res.data.idRoom
      }
      wxRequest.postRequest(getNotPayByRoomUrl, parm).then(result => {
        console.log("获取历史账单", result);
        this.setData({
          
        });
        if (result.data.length > 0) {
          var totalFee = 0;
          var billIdArr = [];
          var billIdStr = "";
          for (var index in result.data) {
            totalFee += result.data[index].talFee;
            billIdArr[index] = result.data[index].id;
            result.data[index].billOverdueTime = result.data[index].billOverdueTime.replace(/-/g, "/");
            result.data[index].billTime = result.data[index].billTime.replace(/-/g, "/");
            result.data[index].namePropertyBill = result.data[index].namePropertyBill.replace(/-/g, "/");
            result.data[index].talFee = result.data[index].talFee.toFixed(2);
          }


          this.setData({
            notPayBillList: result.data,
            totalFee: totalFee.toFixed(2),
            billIdStr: billIdArr.join(",")
          });
        }

      }, error => {
        Common.showToast(error);
      });
    }, error => {
      Common.showToast(error);
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})